package com.kongge.viewdisplayframeworklib.model.queue;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import com.kongge.viewdisplayframeworklib.model.PageNode;
import com.kongge.viewdisplayframeworklib.ui.view.Tabbar;

import java.util.ArrayList;
import java.util.List;

/**
 * author:kongge
 * date:2018/9/12
 * layout:
 * description:
 */

public class PageQueueTabBar extends Tabbar implements ITabbar{

    private List<PageNode> pageNodeList;

    private OnPageSelectChangeListener onPageSelectChangeListener;

    public PageQueueTabBar(Context context) {
        super(context);
    }

    public PageQueueTabBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void setTabList(List<PageNode> pageNodes) {
        if (pageNodes == null || pageNodes.size() == 0) {
            return;
        }
        this.pageNodeList = pageNodes;
        List<String> titles = new ArrayList<>(pageNodes.size());
        for (PageNode pageNode : pageNodes) {
            String title = pageNode.getTitle();
            titles.add(title);
        }
        setTitleList(titles);
    }

    @Override
    public void setPageSelectChangeListener(OnPageSelectChangeListener listener) {
        this.onPageSelectChangeListener = listener;
        setOnTabbarSelectChangeListener(new OnTabbarSelectChangeListener() {
            @Override
            public void onHorizontalScrollTabbarSelectChange(View view, int oldIndex, int curIndex) {
                if (onPageSelectChangeListener != null) {
                    onPageSelectChangeListener.onPageSelectChange(view, oldIndex, curIndex);
                }
            }
        });
    }

    @Override
    public void setSelectIndex(int index) {
        super.setSelectedIndex(index);
    }
}
